<template>
  <div>
    <!-- <el-button @click="childClick">window.parent.a()</el-button> -->
    <el-button type="success" size="small" @click="sonClick">子页面触发</el-button>
    <div>这是通过iframe引的子页面</div>
  </div>
</template>

<script>
export default {
  mounted() {
    window.documentdomain = 'chttp://localhost:8080';
    // 监听父页面向子页面的传参
    window.addEventListener('message', e => {
      console.log('父页面传输过来参数', e.data);
    });
  },
  methods: {
    // 子页面处发向父页面传参
    sonClick() {
      let data = {
        from: 'iframe child page',
        code: 200,
        data: '子页面主动触发通讯'
      };
      window.parent.postMessage(data, '*');
    },
    childClick() {
      window.parent.a();
    }
  }
};
</script>
